<?php
namespace App\Libs\FBAOutboundServiceMWS;
use App\Libs\FBAOutboundServiceMWS\Model\GetFulfillmentOrderRequest;
class OutboundMws
{
    private static $_instance = null;

    private $_fields = ['SellerId',
                        'MWSAuthToken',
                        'Marketplace',
                        'SellerFulfillmentOrderId'];

    public static function getInit(){
        if(!is_object(self::$_instance)){
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    /**
     * Returns a fulfillment order
     * API GetFulfillmentOrder
     * @param array $con
     * @return array
     */
    public function getFulfillmentOrder($con = array())
    {
        $request = $this->_getRequest(new GetFulfillmentOrderRequest(),$con);
        if (!($request instanceof GetFulfillmentOrderRequest)) {
            $request = new GetFulfillmentOrderRequest($request);
        }
        $parameters = $request->toQueryParameterArray();
        $parameters['Action'] = 'GetFulfillmentOrder';
        return $parameters;
    }

    private function _getRequest($request,$con = array()) {
        foreach($con as $k=>$v){
            if($k&&in_array($k,$this->_fields)){
                $setter = "set$k";
                $request->$setter($v);
            }
        }
        return $request;
    }
}
